--require "Common/define"
--require "Logic/Config"
--require "Net/send_Msg"
--require "Net/roleListHandler"
--require "proto/login/message/ReqSelectPlayerMessage"
--
--UIChooseCharactor = {};
--HelperFunc.SetUIEnv(UIChooseCharactor)
--local this = UIChooseCharactor;
--
--this.LuaBehaviour = nil;
--this.transform = nil;
--this.gameObject = nil;
--
----角色信息控件
--this.roleItem = nil;
--this.role_bg = nil;
--this.role_name = nil;
--this.role_level = nil;
--this.role_progress = nil;
--this.role_icon = nil;
--this.role_new = nil;
--this.btn_add = nil;
--this.btn_left = nil;
--this.btn_right = nil;
--this.roleLihui = nil;
--this.roleLihuibg = nil;
--this.btn_Enter = nil;
--
--this.roleData = nil;
----选中的角色
--this.chooseRole = nil;
--this.curHeroConfig = nil;
--
--this.length = 0;
--this.heroConfig = nil;
--this.CreateConfig = nil;
--this.MapConfig = nil;
--
--this.hasInit = false;
--this.defalutRoleId = 1;
--this.curRoleId = 1;
--
--function UIChooseCharactor.Init(data)
--    roleData = data;
--    chooseRole = roleData[1];
--	local name = getUIName(PanelNames. UIChooseCharactor);
--    --panelMgr:Push(name, this.OnCreate,Config.useLocalUI);
--end
--
----定义控件
--function UIChooseCharactor.OnCreate(obj)
--    gameObject = obj;
--    transform = obj.transform;
--    LuaBehaviour = transform:GetComponent('LuaBehaviour');
--
--    --角色信息控件
--    roleItem = transform:Find("Charactor_Item");
--    role_bg = roleItem:Find("Img_Charactor"):GetComponent("Image");
--    role_name = roleItem:Find("Img_Charactor/Name"):GetComponent("TextMeshProUGUI");
--    role_level =  roleItem:Find("Img_Charactor/Level"):GetComponent("TextMeshProUGUI");
--    role_progress = roleItem:Find("Img_Charactor/Progress"):GetComponent("TextMeshProUGUI");
--    role_icon = roleItem:Find("Img_Charactor/Img_Icon"):GetComponent("Image");
--    role_new = roleItem:Find("CharacterImg_Next"):GetComponent("Image");
--    btn_add = roleItem:Find("CharacterImg_Next/Img_New/Img_Add");
--    btn_left = roleItem:Find("Btn_Left");
--    btn_right = roleItem:Find("Btn_Right");
--    roleLihuibg = transform:Find("CharacterImgbg"):GetComponent("Image");
--    roleLihui = transform:Find("CharacterImgbg/CharactorImg"):GetComponent("Image");
--    btn_Enter = transform:Find("EnterBtn");
--    role_bg.gameObject:SetActive(false);
--    role_new.gameObject:SetActive(false);
--    --btn_left.gameObject:SetActive(false);
--    --btn_right.gameObject:SetActive(false);
--    roleLihuibg.gameObject:SetActive(false);
--    btn_Enter.gameObject:SetActive(false);
--
--    this.LocalListenEvent();
--    this.InitFrame();
--
--    --剧情引导先写死
--	local firstGuidanceId = tonumber(Util.GetPlayerPrefs(Util.GetUserName().."Guidance"))
--	if firstGuidanceId == nil then
--		--Util.SetPlayerPrefs(Util.GetUserName().."Guidance", 1)
--		--showUI(PanelNames.UIGuidance, 1)
--    end
--end
--
--function UIChooseCharactor.OnDestroy()
--    this.LocalCloseEvent();
--end
--
--function UIChooseCharactor.LocalListenEvent()
--	LuaBehaviour:AddClick(btn_left.gameObject,this.OnClickLeft);
--	LuaBehaviour:AddClick(btn_right.gameObject,this.OnClickRight);
--    LuaBehaviour:AddClick(btn_Enter.gameObject,this.OnClickEnter);
--    LuaBehaviour:AddClick(btn_add.gameObject,this.OnClickAddNew);
--end
--
--function UIChooseCharactor.LocalCloseEvent()
--	LuaBehaviour:RemoveClick(btn_left.gameObject);
--	LuaBehaviour:RemoveClick(btn_right.gameObject);
--	LuaBehaviour:RemoveClick(btn_Enter.gameObject);
--    LuaBehaviour:RemoveClick(btn_add.gameObject);
--end
--
--function UIChooseCharactor.OnEnable()
--end
--
--function UIChooseCharactor.OnDisable()
--end
--
--function UIChooseCharactor.OnClickLeft()
--    defalutRoleId = defalutRoleId - 1;
--    if defalutRoleId < 1 then
--        defalutRoleId = length + 1;
--    end
--    if defalutRoleId > length + 1 then
--        defalutRoleId = 1;
--    end
--	this.ShowDefalutRole(roleData[defalutRoleId]);
--end
--
--function UIChooseCharactor.OnClickRight()
--    defalutRoleId = defalutRoleId + 1;
--    if defalutRoleId < 1 then
--        defalutRoleId = length + 1;
--    end
--    if defalutRoleId > length + 1 then
--        defalutRoleId = 1;
--    end
--	this.ShowDefalutRole(roleData[defalutRoleId]);
--end
--
--function UIChooseCharactor.OnClickEnter()
--    local iswhite = indexofTable(Config.whitemUserId,Config.SDKUserId) >= 1;
--    if not Config.isServerOpen and not iswhite then
--        UISysTips.AddMsg("服务器未开启");
--        return;
--    end
--    if chooseRole ~= nil then
--        for i=1, #roleData do
--            local v = roleData[i];
--            if(tostring(v.playerId) == tostring(chooseRole.playerId)) then
--                if(v.level >= 4) then
--                    LuaHelper.GetGameManager():startCheckMapPrefab(function()
--
--                        this.enterGame(v.playerId, i);
--
--                    end);
--                else
--                    this.enterGame(v.playerId, i);
--                end
--                break;
--            end
--        end
--    end
--end
--
--function UIChooseCharactor.OnClickAddNew()
--    showUI(PanelNames.UICreateName);
--end
--
--function UIChooseCharactor.Reset()
--end
--
----初始化界面
--function UIChooseCharactor.InitFrame()
--	chooseRole = nil;
--	if heroConfig == nil then
--		heroConfig = G.dataTable["t_hero"];
--	end
--	if CreateConfig == nil then
--		CreateConfig = G.dataTable["t_createCharacter"];
--    end
--    if MapConfig == nil then
--		MapConfig = G.dataTable["t_stage"];
--    end
--    length =  #roleData;
--
--    --获取上次登录的角色Id
--	defalutRoleId = tonumber(Util.GetPlayerPrefs(Util.GetUserName().."ChooseRole"))
--    if defalutRoleId == nil or defalutRoleId > length then
--		defalutRoleId = 1
--	end
--    if defalutRoleId > #roleData then
--        defalutRoleId = 1;
--    end
--    curRoleId = defalutRoleId;
--    this.ShowDefalutRole(roleData[defalutRoleId]);
--end
--
--function UIChooseCharactor.ShowDefalutRole(data)
--    if data ~= nil then
--        this.ChooseAndShowInfo(data);
--    else
--        this.ShowAddNew();
--    end
--end
--
--function UIChooseCharactor.ChooseAndShowInfo(data)
--    local roleInfo = G.serverData["roleInfo"];
--	chooseRole = data;
--    curHeroConfig = heroConfig[tostring(chooseRole["leaderModelId"])];
--    if curHeroConfig ~= nil then
--        role_bg.gameObject:SetActive(true);
--        role_new.gameObject:SetActive(false);
--        roleLihuibg.gameObject:SetActive(true);
--        btn_Enter.gameObject:SetActive(true);
--
--        local imageName = curHeroConfig.f_HeroDrawing;
--        local imageBGName = string.format("%02d", curHeroConfig.f_HeroType);
--        resMgr:LoadSpritePrefab(imageName,function(sp)
--            roleLihui.sprite = sp;
--        end);
--        resMgr:LoadSpritePrefab(imageBGName,function(sp)
--            roleLihuibg.sprite = sp;
--        end);
--        --role_name.text = curHeroConfig.f_HeroName;
--        role_name.text = chooseRole["name"];
--        role_level.text = string.format(getLanguage("Level"), chooseRole["level"]);
--        resMgr:LoadIconFromPrefab("CreateAtlas", "hero_"..curHeroConfig.f_HeroID, function(sp)
--            role_icon.sprite = sp;
--        end);
--    end
--    if MapConfig ~= nil then
--        local curMapConfig = MapConfig[tostring(chooseRole["map"])];
--        if curMapConfig ~= nil then
--            role_progress.text = getLanguage(curMapConfig.f_StageName);
--        end
--    end
--end
--
--function UIChooseCharactor.ShowAddNew()
--    role_bg.gameObject:SetActive(false);
--    role_new.gameObject:SetActive(true);
--    roleLihuibg.gameObject:SetActive(false);
--    btn_Enter.gameObject:SetActive(false);
--end
--
--function UIChooseCharactor.enterGame(playerid, roleIndex)
--    local reqlogin = ReqSelectPlayerMessage.New();
--    reqlogin.playerId = playerid;
--    sendReqMessage(reqlogin);
--    Util.SetPlayerPrefs(Util.GetUserName().."ChooseRole", tostring(roleIndex))
--end
--
--return UIChooseCharactor;